import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { getEntireRommlist } from "../../services/modules/entire";

export const fetchEntireData = 
    createAsyncThunk('fetchEntire', (payload, { dispatch }) => {
    getEntireRommlist(payload.offset,payload.size).then(res => {
        dispatch(changeRoomlist(res.list)); 
        dispatch(changeTotalCount(res.totalCount));
    })
      
 })
 

const entireSlice = createSlice({
    name:"entire",
    initialState: {
        currentpage: 0,
        roomlist: [],
        totalCount: 0,
        isLoading:false,
    },
    reducers: {
        changeRoomlist(state, { payload })
        {
            state.roomlist = payload;
        },
        changeTotalCount(state, { payload })
        {
            state.totalCount = payload;
        },
        changeCurrentPage(state, { payload })
        {
            state.currentpage = payload;
        },
        changeloading(state,{payload})
        {
            state.isLoading = payload;
        }
    }
})

export default entireSlice.reducer;
export const { changeRoomlist,changeCurrentPage,changeTotalCount,changeloading} = entireSlice.actions;
